package com.testMain;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 贾明祯
 * @ClassName VacationDayCalculate
 * @Date 2021/3/22 10:09
 * @Introduce 获取指定日期
 */
public class VacationDayCalculate {


    public static void main(String[] args) {
        try{
            String beginDate = "2021-03-01";//开始时间
            String endDate = "2021-03-31";//结束时间
            String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar cal = Calendar.getInstance();
            cal.setTime(sdf.parse(beginDate));

            for (long d = cal.getTimeInMillis(); d <= sdf.parse(endDate).getTime(); d = get_D_Plaus_1(cal)) {
                System.out.println(sdf.format(d));
                Date date = new Date(d);
                cal.setTime(new Date(d));
                int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
                System.out.println(weeks[week_index]);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static long get_D_Plaus_1(Calendar c) {
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
        return c.getTimeInMillis();
    }

}
